﻿using System;
using System.Drawing;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Media.Imaging;
using Microsoft.Wpf.Samples.BaseLibrary;
using System.Windows.Interop;
using SnowFlakesWPF;

namespace OnScreenPaintWPF
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            this.Loaded += (s, e) =>
                {
                    GlassEffectHelper.EnableGlassEffect(this);
                };

            Bitmap bmp = CaptureScreen();

            _image.Source = CreateBitmapSource(bmp);

            // Switch to fullscreen
        }

        public Bitmap CaptureScreen()
        {
            Bitmap bmp = new Bitmap(SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height);
            Graphics g = Graphics.FromImage(bmp);
            g.CopyFromScreen(0, 0, 0, 0, bmp.Size);
            g.Dispose();
            return bmp;
        }

        public static BitmapSource CreateBitmapSource(System.Drawing.Bitmap bmp)
        {
            return Imaging.CreateBitmapSourceFromHBitmap(
                bmp.GetHbitmap(), 
                IntPtr.Zero, 
                Int32Rect.Empty,
                BitmapSizeOptions.FromEmptyOptions());
        }

        private void _fullscreenButton_Click(object sender, RoutedEventArgs e)
        {
            FullScreenHelper.GoFullscreen(this);
        }

        private void _closeButton_Click(object sender, RoutedEventArgs e)
        {
            App.Current.Shutdown();
        }

    }
}
